//车辆状态机
const axios = require('axios')
module.exports = {
    namespaced: true,
    state: {
        carlist: [],
        several: 4,
        yeshu: 1,
        pages: '',
        rowss: '',
        lei: '',
        leirong: '',
        userId: '',
        audit:'待审核',
    },
    mutations: {
        //获取所有车辆信息
        getcar(state, data) {
            state.carlist = data.data;//所有车辆数据
            state.several = data.several;//显示多少条数据
            state.rowss = data.rowss;//一共有多少条数据
            state.pages = data.pages;//一共有多少页
            state.yeshu = data.yeshu//当前页数
        },
        xiaye(state) {
            if (state.yeshu < state.pages) {
                state.yeshu++
            }
        },
        shangye(state) {
            if (state.yeshu >= 1) {
                state.yeshu--
            }
        },
        weiye(state){
            state.yeshu=state.pages
        },
        shouye(state){
            state.yeshu=1
        },
        cha(state,data){
            state.lei=data.lei;
            state.leirong=data.leirong
        },
    },
    actions: {
        //获取所有车辆信息
        getcaractions(context, data1) {
            axios.get('/car/getCarAll', { params: { several: context.state.several, yeshu: context.state.yeshu, lei: context.state.lei, leirong: context.state.leirong, merchantId: data1 } }).then(({ data }) => {
                context.commit('getcar', data)
            })
        },
        //下一页
        overleaf(context, data) {
            context.commit("xiaye")
            context.dispatch('getcaractions')
        },
        //上一页
        pageup(context) {
            context.commit("shangye")
            context.dispatch('getcaractions')
        },
        //尾页
        trailer(context){
            context.commit('weiye')
            context.dispatch('getcaractions')
        },
        //首页
        homepage(context){
            context.commit('shouye')
            context.dispatch('getcaractions')
        },
        //查询
        chaxun(context,data){
            context.commit('cha',data)
            context.dispatch('getcaractions')
        },
    },
    getter: {
    }
}